package cn.edu.zut.qixiang.flink;

import lombok.Data;

/**
 * @author 86178
 */
@Data
public class TemperatureAccumulator {
    private String district;
    private double sumTemperature = 0.0;
    private double maxTemperature = Double.MIN_VALUE;
    private double minTemperature = Double.MAX_VALUE;
    private long count = 0;

    public void addTemperature(double temperature) {
        this.sumTemperature += temperature;
        this.maxTemperature = Math.max(this.maxTemperature, temperature);
        this.minTemperature = Math.min(this.minTemperature, temperature);
        this.count++;
    }

    public void merge(TemperatureAccumulator other) {
        this.sumTemperature += other.sumTemperature;
        this.maxTemperature = Math.max(this.maxTemperature, other.maxTemperature);
        this.minTemperature = Math.min(this.minTemperature, other.minTemperature);
        this.count += other.count;
    }

    public double getAvgTemperature() {
        return count == 0 ? 0.0 : sumTemperature / count;
    }
}